package de.fzi.kasma.learner.genetic;

import de.fzi.kasma.learner.util.Util;
import ec.EvolutionState;
import ec.Individual;
import ec.Species;
import ec.simple.SimpleFitness;
import ec.util.Parameter;

public class SLSpecies extends Species{

	/**
	 * 
	 */
	private static final long serialVersionUID = 109452133957318121L;



	public int coeffsNumber;
	public static final String P_SLSPECIES = "species";
	public static double min = 0.0d;
	public static double max = 1.0d;

    
	@Override
    public void setup(final EvolutionState state, final Parameter base)
        {
        super.setup(state,base);

        // check to make sure that our individual prototype is a SLIndividual
        if (!(i_prototype instanceof SLIndividual))
            state.output.fatal("The Individual class for the Species " + getClass().getName() + " is must be a subclass of SLIndividual.", base );
        
        coeffsNumber =  	((RLInitializer) state.initializer).getDataset().getNumberOfExamples();
        
        }    

    public Individual newIndividual(EvolutionState state, int thread) 
        {
        SLIndividual newind = new SLIndividual();

    	double[] newCoeffs = new double[coeffsNumber];
    	
    	for(int i =0; i<newCoeffs.length; i++)
    		newCoeffs[i] = Util.nextDoubleInRange(min, max);

    	newind.coeffs = newCoeffs;
    	SimpleFitness fit = new SimpleFitness();
    	fit.setFitness(state, 0, false);
    	newind.fitness = fit;
        newind.reset( state, thread);

        return newind;
        }

	@Override
	public Parameter defaultBase() {
		
        return SLDefaults.base().push(P_SLSPECIES);
	}
}


	


